package xps.and.uudaijia.userclient.view.activity;

import android.app.Activity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import xps.and.uudaijia.userclient.R;
import xps.and.uudaijia.userclient.StringCommond;
import xps.and.uudaijia.userclient.util.CommonUtils;
import xps.and.uudaijia.userclient.view.base.BaseActivity;
import xps.and.uudaijia.userclient.view.fragment.OrderDaijiaFragment;
import xps.and.uudaijia.userclient.view.fragment.OrderPingCheFragment;

public class MyOrderActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.actionbar_iv_back)
    ImageView actionbarIvBack;
    @BindView(R.id.actionbar_tv_title)
    TextView actionbarTvTitle;
    @BindView(R.id.actionbar_tv_right)
    TextView actionbarTvRight;
    @BindView(R.id.actionbar_al)
    AutoRelativeLayout actionbarAl;
    @BindView(R.id.tab_container)
    FrameLayout tabContainer;
    public Activity aActivity;
    OrderDaijiaFragment orderDaijiaFragment;
    OrderPingCheFragment orderPingCheFragment;
    @BindView(R.id.v_gap_line)
    View vGapLine;
    @BindView(R.id.tv_daijia)
    TextView tvDaijia;
    @BindView(R.id.v_indicator_daijia)
    View vIndicatorDaijia;
    @BindView(R.id.al_daijia)
    AutoLinearLayout alDaijia;
    @BindView(R.id.tv_pinche)
    TextView tvPinche;
    @BindView(R.id.v_indicator_pinche)
    View vIndicatorPinche;
    @BindView(R.id.al_pinche)
    AutoLinearLayout alPinche;
    @BindView(R.id.al_above_service_type)
    AutoLinearLayout alAboveServiceType;

    @Override
    protected int getLayout() {
        return R.layout.activity_order;
    }

    @Override
    protected void setData() {

    }

    @Override
    protected void init() {
        ButterKnife.bind(this);
        actionbarIvBack.setOnClickListener(this);
        actionbarTvTitle.setText("订单列表");
        orderDaijiaFragment = new OrderDaijiaFragment();

        CommonUtils.replaceFragment(R.id.tab_container, orderDaijiaFragment, getSupportFragmentManager());
        aActivity = this;
    }

    @OnClick({R.id.tv_pinche, R.id.tv_daijia})
    public void onViewClicked(View v) {
        switch (v.getId()) {
            case R.id.tv_pinche:
                toPincheMode();
                orderPingCheFragment = new OrderPingCheFragment();
                CommonUtils.replaceFragment(R.id.tab_container, orderPingCheFragment, getSupportFragmentManager());
                break;
            case R.id.tv_daijia:
                toDaijiaMode();
                orderDaijiaFragment = new OrderDaijiaFragment();
                CommonUtils.replaceFragment(R.id.tab_container, orderDaijiaFragment, getSupportFragmentManager());
                break;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.actionbar_iv_back:
                finish();
                break;
        }
    }

    void toPincheMode() {
        resetLable();
        vIndicatorPinche.setVisibility(View.VISIBLE);
        EventBus.getDefault().post(StringCommond.ON_GLOBALLAYOUT_CHANGES);
    }

    void resetLable() {
        vIndicatorDaijia.setVisibility(View.INVISIBLE);
        vIndicatorPinche.setVisibility(View.INVISIBLE);
    }

    void toDaijiaMode() {
        resetLable();
        vIndicatorDaijia.setVisibility(View.VISIBLE);
        EventBus.getDefault().post(StringCommond.ON_GLOBALLAYOUT_CHANGES);
    }


}
